package com.asman.vr.network

import android.app.Application
import android.content.Context
import androidx.annotation.VisibleForTesting
import com.asman.vr.dto.*
import java.util.concurrent.Executor

/**
 * Super simplified service locator implementation to allow us to replace default implementations
 * for testing.
 * 超级简化的服务定位器实现，允许我们替换默认的测试实现。
 */
interface ServiceLocator {
    companion object {

        private val LOCK = Any()
        private var instance: ServiceLocator? = null

        fun instance(context: Context): ServiceLocator {
            synchronized(LOCK) {
                if (instance == null) {
                    instance =
                        DefaultServiceLocator(app = context.applicationContext as Application)
                }
                return instance!!
            }
        }

        /**
         * Allows tests to replace the default implementations.
         * 允许测试替换默认实现。
         */
        @VisibleForTesting
        fun swap(locator: ServiceLocator) {
            instance = locator
        }
    }

    fun getNetworkExecutor(): Executor

    fun getDiskIOExecutor(): Executor

    fun getMainApi(): Api

    fun getWorkerApi(): ApiWorker//小牛师傅接口

    fun getProjectRepository(): ProjectRepository//---1

    fun getAccountRepository(): AccountRepository

    fun getAddressRepository(): AddressRepository

    fun getPayRepository(): PayRepository

    fun getMessageRepository(): MessageRepository

    fun getContractRepository(): ContractRepository

    fun getBaseDataRepository(): BaseDataRepository

    fun getSchemeRepository(): SchemeRepository

    fun getOperateRepository(): OperateRepository

    fun getCustomMyHomeRepository(): CustomMyHomeRepository

    fun getCommentRepository(): CommentRepository

    fun getScoreRepository(): ScoreRepository

    fun getCollectionRepository(): CollectionRepository

    fun getDesignerRepository(): DesignerRepository

    fun getGoodsDetailRepository(): GoodsDetailRepository

    fun getCallAnswerRepository(): CallAnswerRepository

    fun getCustomerRepository(): CustomerRepository
}
